﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace WEITUO
{
    public delegate void MyDelegate();

    public delegate void ee(int a,int b,int c);

    public class Program
    {
        public static int c;

        static void Main(string[] args)
        {
            float te = -4.7f;

            Console.Write("{0}", Math.Abs(te));
            int a, b;
            a = 10;
            b = 20;
            c = 0;
            da da = new da();
            MyDelegate myDelegate = new MyDelegate(MyMethod);
            myDelegate.Invoke(); // Invoke the delegate    
            myDelegate = null;
            MyMethod2(myDelegate);
            MyMethod3(a, b, c);
            Console.Write("{0}",c);
        }

        // A method matching the delegate signature    
        public static void MyMethod()
        {
            Console.WriteLine("fasa");
        }
        public static void MyMethod2(MyDelegate myDelegate) //invoke the delegate  
        {
            myDelegate -= () => MyMethod(); // Invoke the delegate  
            myDelegate += () => { Console.WriteLine("cs"); };
            myDelegate += () => { Console.WriteLine("de"); };
            myDelegate += () => { Console.WriteLine("de"); };
            myDelegate?.Invoke(); // Safely invoke the delegate  
        }
        public static void MyMethod3(int a,int b,int c) //invoke the delegate
        {
            Program p = new Program();
            da da = new da();    
            ee ee = null;
            ee += (q,w,e) => { da.sa(a,b,out c); };
            ee += (q, w, e) => { Program.c = da.sa(a,b,out c); };
            ee(c, b, a);
        }
    }
    public class da
    {
        public int sa(int a,int b,out int c)
        {
            c = a + b;
            return a + b;
        }
    }
}
